package gdconf

import (
	"server_cluster/common/logger"
)

// 功能开放配置表

const (
	OpenStateCondFinishParentQuest = 1 // 完成父任务 参数1:父任务id
	OpenStateCondPlayerLevel       = 2 // 达到指定玩家等级 参数1:玩家等级
	OpenStateCondFinishSubQuest    = 3 // 完成父任务 参数1:子任务id
)

type OpenStateConfig struct {
	OpenStateId int32         `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 功能开放id
	CondList    IntArrayArray `csv:"Cond,omitempty"`                            // 条件列表
}

func (o *OpenStateConfig) TableName() string {
	return "config_open_state"
}

func (g *GameDataConfig) saveOpenStateConfig() {
	saveTableToDb[OpenStateConfig](g.Db, readTable[OpenStateConfig](g.CsvPathPrefix+"Func.csv"))
}

func (g *GameDataConfig) loadOpenStateConfig() {
	g.GameDataMaps.OpenStateConfigMap = make(map[int32]*OpenStateConfig)
	for _, openStateConfig := range loadTableFromDb[OpenStateConfig](g.Db) {
		g.GameDataMaps.OpenStateConfigMap[openStateConfig.OpenStateId] = openStateConfig
	}
	logger.Info("OpenStateConfig Count: %v", len(g.GameDataMaps.OpenStateConfigMap))
}

func GetOpenStateConfig(openStateId int32) *OpenStateConfig {
	value, exist := CONF.GameDataMaps.OpenStateConfigMap[openStateId]
	if !exist {
		logger.Error("[ConfigNotFound] OpenStateConfig, openStateId: %v", openStateId)
		return nil
	}
	return value
}

func GetOpenStateConfigMap() map[int32]*OpenStateConfig {
	return CONF.GameDataMaps.OpenStateConfigMap
}
